
import java.io.PrintWriter;

import javax.servlet.http.*;  // provides servlet functionality
import javax.servlet.*;	      // ditto
import javax.*;

public class Bridge {

	public static void logUserIn(String email, HttpSession session)
	{
		session.setAttribute(Constants.loggedInUserAttributeName, email);
		session.setAttribute(Constants.loginAttemptAttributeName, new Integer(0));
		session.setAttribute(Constants.cartAttributeName, new CartOfItems());
		session.removeAttribute(Constants.shippingAddressAttributeName);
	}
	
	public static void logUserOut(HttpSession session)
	{
		session.removeAttribute(Constants.loggedInUserAttributeName);
		session.setAttribute(Constants.loginAttemptAttributeName, new Integer(0));
		session.removeAttribute(Constants.cartAttributeName);
		session.removeAttribute(Constants.shippingAddressAttributeName);
	}
	
	public static boolean hasBeenToMainPage(HttpSession session, PrintWriter out)
	{
		if ( session.getAttribute( "beenToMainPage" ) == null 
			|| ! ((Boolean)session.getAttribute( "beenToMainPage" )).booleanValue() )
		{
			out.print("<html><head><title>FabFlixs</title>" +
					"<meta http-equiv=\"REFRESH\" content=\"0;url=../Main_Page.jsp\"> " +
					"</head></html>");
			return false;
		}
		
		return true;
	}
	
}
